﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BEX.RuleMonitor
{
    public class NotificationManager
    {
        public NotificationManager()
        {
        }

        private string BuildNotificationMsg(AlertRule toNotify)
        {
            var _message = string.Empty;

            switch (toNotify.GetType().ToString())
            {
                case ("BEX.RuleMonitor.PercentageRule"):
                    _message = "(PercentRule) " + ((PercentageRule)toNotify).Percent + "% in " + (((PercentageRule)toNotify).TimeSpan / 60).ToString() + " minutes";
                    break;
                case ("BEX.RuleMonitor.FlatAmountRule"):
                    _message = "(FlatRule) " + ((FlatAmountRule)toNotify).Amount + " BTC";
                    break;
                case ("BEX.RuleMonitor.IncrementRule"):
                    _message = "(IncrementRule) " + ((IncrementRule)toNotify).Increment + " in " + (((IncrementRule)toNotify).TimeSpan / 60).ToString() + " minutes";
                    break;
                case ("BEX.RuleMonitor.ArbitrageRule"):
                    _message = "(ArbitrageRule) " + ((ArbitrageRule)toNotify).Percent;
                    break;
                default:
                    _message = "Unknown";
                    break;
            }

            return _message;
        }

        public void GenerateNotifications(AlertRule toNotify)
        {
            var _accounts = toNotify.GetAccountIDList();

            var _m = BuildNotificationMsg(toNotify);

            foreach (int account in _accounts)
            {
                var _q = new NotificationQueue(_m, toNotify.ID, toNotify.GetType().ToString(), account, toNotify);

                _q.Create();
            }
        }
    }
}
